package com.project.service.impl;

import com.project.bean.ProductBean;
import com.project.mapper.IProductMapper;
import com.project.service.IProductService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Title: ProductServiceImpl
 * @Package: com.project.service
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/7/13 - 17:31
 */
@SuppressWarnings("all")
public class ProductServiceImpl extends BaseService implements IProductService {
    @Override
    public void add(ProductBean productBean) {
        SqlSession session=this.getSession();
        IProductMapper mapper=session.getMapper(IProductMapper.class);
        mapper.add(productBean);
        session.commit();
        session.close();
    }

    @Override
    public void del(Integer id) {
        SqlSession session=this.getSession();
        IProductMapper mapper=session.getMapper(IProductMapper.class);
        mapper.del(id);
        session.commit();
        session.close();
    }

    @Override
    public void update(Integer id, Integer price) {
        SqlSession session=this.getSession();
        IProductMapper mapper=session.getMapper(IProductMapper.class);
        mapper.update(id,price);
        session.commit();
        session.close();
    }

    @Override
    public List<ProductBean> findAll() {
        SqlSession session=this.getSession();
        IProductMapper mapper=session.getMapper(IProductMapper.class);
        List<ProductBean>productBeanList=mapper.findAll();
        session.commit();
        session.close();
        return productBeanList;
    }

    @Override
    public ProductBean findById(Integer id) {
        SqlSession session=this.getSession();
        IProductMapper mapper=session.getMapper(IProductMapper.class);
        ProductBean productBean=mapper.findById(id);
        session.commit();
        session.close();
        return productBean;
    }
}
